   <?php 

/* ------------------------------------------------------------
 * Page: Payment Form
 * Author: Gustavo Lozano & Fredrik Kronander
 * Description: Store and show personal data submitted in previous stage and allow user to submitt payment details.
 * 
 **------------------------------------------------------------*/

   
   	require_once 'source/User.php';	
	
	if(!isset($_SESSION["userinformation"]))
	{
		$user = new User();	
	}
	else 
	{
		$user = unserialize($_SESSION["userinformation"]);
		
	}
	
	echo "<strong>Complete Booking - Stage 2 of 4 - Payment Details<br/><br/>Here is your entered personal information, please enter your payment details below:</strong>";	
	
	//Store submitted data into the $user object and print it at the same time.
	
	$userarray =array("givenName", "familyName", "address1", "address2", "suburb", "state", "postcode", "country", "email", "mobilePhone", "businessPhone", 	"workPhone");
	$userarraynames =array("Given name", "Family name", "Address 1", "Address 2", "Suburb", "State", "Postcode", "Country", "E-mail", "Mobile phone", 	"Business 		phone", "Work phone");
	
	echo "<table width=50%' border='0' cellspacing='2' cellpadding='2'>";
	

	for ($counter = 0; $counter < count($userarray); $counter++)
	{
		if(isset($_REQUEST[$userarray[$counter]]) && $_REQUEST[$userarray[$counter]] != "" )
		{
			$user->$userarray[$counter]=$_REQUEST[$userarray[$counter]];
			echo "<tr height='23px'><td><strong>".$userarraynames[$counter].":</strong></td><td>".$user->$userarray[$counter]."</td></tr>";
		}
	
		
	}
				
	echo "</table>";
	
	$_SESSION['userinformation']=serialize($user);
		  
?>

<script Language="Javascript">
//Rules for jQuery validation of the form.
$(document).ready(function(){
            
    $("#Form").validate({
    	rules: {
    	
    		txtNameOnCard: {
    			required: true,
    		},
    		
    		txtCardNumber: {
    			required: true,
    			creditcard2: function(){return $('#txtCardType').val();} 	,
    		},
    		
    		txtCVVNumber: {
    			required: true,
    			number: true,
    		}
    	
        }
    	
    	
    });

  });
  
  //Check that expire date is in the future.
        function   validateExp() 
        {
                    var minMonth = new Date().getMonth() + 1;
                    var minYear = new Date().getFullYear();
                    var month = $('#txtMonth').val();
                    var year = $('#txtYear').val();

                    if ((year > minYear) || (((year == minYear)) && (month >= minMonth))) 
                    {
                    	$('#errorExp').html("");
                        return true;
                    } 
                    else {
                   		$('#errorExp').html("Please select a future date");
						
                        return false;
                    }
                }
   
</script>




<form name="Form" id="Form" action="index.php?content=ReviewBooking" method="post" onsubmit="return validateExp()">
	<table width="100%" border="0" cellspacing="2" cellpadding="2">
		<tr>
			<td colspan=2>
				<table width="100%" border="0" cellspacing="0" cellpadding="0">
					<tr height="23px">
						<td>&nbsp;<strong>Please provide us with your payment details</strong></td>
					</tr>
					<tr height="20" valign="bottom">
						<td><span class="style1">Your information is taken securely using 128-bit encryption.</span></td>
					</tr>
				</table>
			</td>
		</tr>
		<tr>
			<td colspan=2 height="10"></td>
		</tr>
		<tr>
			<td width="30%" align="right"><strong>Credit Card Type:</strong>&nbsp;</td>
			<td width="70%">
			
			<select id="txtCardType" name="txtCardType">
				<option value="AmEx">AmEx</option>
				<option value="DinersClub">DinersClub</option>
				<option value="Maestro">Maestro</option>
				<option value="MasterCard">MasterCard</option>
				<option value="Visa">Visa</option>
				<option value="VisaElectron">VisaElectron</option>
			</select>
			
			</td>
		</tr>
		<tr>
			<td align="right">
				<strong>Name as on Credit Card:</strong>&nbsp;
			</td>
			<td>
				<input type="text" name="txtNameOnCard" id="txtNameOnCard" size="35" value="" />* 
			</td>
		</tr>
		<tr>
			<td align="right">
				<strong>Credit Card Number:</strong>&nbsp;
			</td>
			<td>
				<input type="text" name="txtCardNumber" id="txtCardNumber" size="35" value="" />*
			</td>
		</tr>
		<tr>
			<td align="right">
				<strong>Card Expiry Date:</strong>&nbsp;
			</td>
			<td>

				<select onchange="return validateExp()" name="txtMonth" id="txtMonth" >
					<option value="01">January</option>
					<option value="02">February</option>
					<option value="03">March</option>
					<option value="04">April</option>
					<option value="05">May</option>
					<option value="06">June</option>
					<option value="07">July</option>
					<option value="08">August</option>
					<option value="09">September</option>
					<option value="10">October</option>
					<option value="11">November</option>
					<option value="12">December</option>
				</select>
			&nbsp;&nbsp;
				<select name="txtYear" id="txtYear" >
					<option value="2011">2011</option>
					<option value="2012">2012</option>
					<option value="2013">2013</option>
				</select>
				<div id="errorExp"></div>
			</td>
		</tr>
		<tr>
			<td align="right">
				<strong>CVV Number:</strong>&nbsp;
			</td>
			<td>
				<input type="text" name="txtCVVNumber" id="txtCVVNumber" size="4" maxlength="4" value="" />
			*</td>
		</tr>
		<tr>
			<td>&nbsp;</td>
			<td>
				<input type="Submit" name="btnSubmit" id="btnSubmit" value="Stage 3 - Review Bookings and Details" />&nbsp;&nbsp;
				<input type="Reset" name="btnReset" id="btnReset" value="Reset" />
			</td>
		</tr>
		<tr>
			<td colspan=2 >&nbsp;</td>
		</tr>
	</table>
</form>

